package br.com.srv.security;

import java.security.Principal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import HTTPClient.HTTPConnection;
import br.com.srv.model.VeiculoTO;

public class SecurityPrincipal implements Principal {
	private String name;

	private String password;

	private String arenaSessionId;

	private String loginResponse;

	private String userId;

	private Integer clienteId;

	private String typeId;

	private List veiculos;
	
	private Integer clienteIdBD;
	
	private Integer tipoClienteIdBD;

	private HTTPConnection connection;

	public String getDescVeiculo(String id) {
		if (id == null) {
			Map veiculo = (Map) veiculos.get(0);
			return veiculo.get("DESC").toString(); 
		}
		for (Iterator iter = veiculos.iterator(); iter.hasNext();) {
			Map veiculo = (Map) iter.next();
			if (veiculo.get("ID").equals(id)) {
				return veiculo.get("DESC").toString(); 
			}
		}
		return null;
	}
	
	public Long getEquipamentoID(Long veiculoID) {
		for (Iterator iter = veiculos.iterator(); iter.hasNext();) {
			Map veiculo = (Map) iter.next();
			if (veiculo.get("ID").equals(veiculoID.toString())) {
				return Long.valueOf(veiculo.get("EQUIPMENT_SERIAL").toString()); 
			}
		}
		return null;
	}
	
	public String toString() {
		return getName();
	}
	
	public String getArenaSessionId() {
		return arenaSessionId;
	}

	public void setArenaSessionId(String arenaSessionId) {
		this.arenaSessionId = arenaSessionId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public HTTPConnection getConnection() {
		return connection;
	}

	public void setConnection(HTTPConnection connection) {
		this.connection = connection;
	}

	public String getLoginResponse() {
		return loginResponse;
	}

	public void setLoginResponse(String loginResponse) {
		this.loginResponse = loginResponse;
	}

	public Integer getClienteId() {
		return clienteId;
	}

	public void setClienteId(Integer clienteId) {
		this.clienteId = clienteId;
	}

	public String getTypeId() {
		return typeId;
	}

	public void setTypeId(String typeId) {
		this.typeId = typeId;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public List getVeiculos() {
		return veiculos;
	}
	
	public List<VeiculoTO> getVeiculosAsTO() {
		List<VeiculoTO> list = new ArrayList<VeiculoTO>();
		for (Iterator iter = veiculos.iterator(); iter.hasNext();) {
			Map map = (HashMap) iter.next();
			Integer realId = new Integer(map.get("ID").toString());
			VeiculoTO veiculoTO = new VeiculoTO();
			veiculoTO.setRealId(realId);
//			veiculoTO.setId(realId);
			veiculoTO.setDescricao(map.get("DESC").toString());
			list.add(veiculoTO);
		}
		return list;
	}

	public void setVeiculos(List veiculos) {
		this.veiculos = veiculos;
	}

	public Integer getClienteIdBD() {
		return clienteIdBD;
	}

	public void setClienteIdBD(Integer clienteIdBD) {
		this.clienteIdBD = clienteIdBD;
	}

	public Integer getTipoClienteIdBD() {
		return tipoClienteIdBD;
	}

	public void setTipoClienteIdBD(Integer tipoClienteIdBD) {
		this.tipoClienteIdBD = tipoClienteIdBD;
	}

}
